//app.js
App({
  onLaunch: function () {
    //调用API从本地缓存中获取自定义个人信息
    //设置缓存ID来标识缓存是否被删除或用户更换手机，若是则重新拉取
    //向服务器发起请求拉取id并与缓存id比对
    var baseInfo = wx.getStorageSync('baseInfo') || {};
    this.globalData.baseInfo = baseInfo;
  },
  getUserInfo: function(cb){
    var that = this
    if(this.globalData.userInfo){
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
              that.globalData.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
    }
  },
  setUserInfo: function(cb){
    var self = this;
    // self.set
  },
  getBaseInfo: function(cb){
    var that = this;
    if(this.globalData.baseInfo){
      typeof cb == "function" && cb(this.globalData.baseInfo)
    } else {
      //调用微信请求个人信息缓存
      wx.getStorage({
        key: 'baseInfo',
        success: function(res){
          console.log(res.data)
          //更改全局数据池
          that.globalData.baseInfo = res.data;
          typeof cb == "function" && cb(this.globalData.baseInfo)
        }
      })
    }
  },
  globalData:{
    userInfo: null,//微信个人信息
    baseInfo: null,//自定义个人信息
  }
})